package com.bidbid.home.web;

import java.text.ParseException;
import java.text.SimpleDateFormat;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;

import com.bidbid.security.domain.User;
import com.bidbid.security.service.IUserService;

@Controller
public class RegisterController {
	
	@Autowired
	private IUserService userService;
	
	@RequestMapping(value="/home/register.html",method=RequestMethod.GET)
	public String registerPrepare(){
		return "common/register";
	}
	
	@RequestMapping(value="/home/register.html",method=RequestMethod.POST)
	public String registerSubmit(ModelMap modelMap,
			@RequestParam(value="loginName",required=true)String loginName,
			@RequestParam(value="trueName",required=false)String trueName,
			@RequestParam(value="password",required=true)String password,
			@RequestParam(value="gender",required=true)Integer gender,
			@RequestParam(value="area",required=true)String area,
			@RequestParam(value="birth",required=true)String birth) throws ParseException{
		
		User user=new User();
		
		user.setArea(area);
		user.setBirth((new SimpleDateFormat("YYYY-mm-dd")).parse(birth));
		user.setGender(gender);
		user.setLoginName(loginName);
		user.setPassword(password);
		user.setTrueName(trueName);
		
		modelMap.put("user", user);
		return "home";
		
	}
	
	
	
}
